//Page Object
const url = require('../../config/config.js')
Page({
    data: {
        userInfo: {}

    },
    //options(Object)
    onLoad: function() {
        const userInfo = wx.getStorageSync("userInfo");
        this.setData({
            userInfo
        })
    },
    onShow() {
        //读取token，如果token不存在,直接不给予返回
        const token = wx.getStorageSync("token");
        console.log(token)
        if (!token) {
            wx.navigateTo({
                url: '/pages/login/index'
            });
        }
    },
    // 一键退出登录
    handlelayout() {
        const header = {
            'content-type': 'application/json',
            'Cookie': "JSESSIONID=" + wx.getStorageSync("token") //读取cookie
        }
        wx.request({
            url: url.b.logout,
            data: {},
            header: header,
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                console.log(result)
                wx.removeStorageSync("token");
                wx.navigateTo({
                    url: '/pages/login/index',
                });
            },
            fail: () => {},
            complete: () => {}
        });
    }
});